package com.zues.samples.service.Impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zues.samples.dao.ScoreDAO;
import com.zues.samples.model.PagerModel;
import com.zues.samples.model.Score;
import com.zues.samples.service.ScoreService;
import com.zues.samples.service.modelVO.ScoreVO;

@Service
public class ScoreServiceImpl implements ScoreService{
	
	@Autowired
	private ScoreDAO scoreDAO;

	@Override
	public List<Score> findByAllScore() throws Exception {
		return scoreDAO.findByAllScore();
	}

	@Override
	public PagerModel<ScoreVO> findAllByPage() {
		return scoreDAO.findAllByPage();
	}

	@Override
	public ScoreVO showScore(Integer scoreId) throws Exception  {
		ScoreVO scoreVO = new ScoreVO();
		Score score = scoreDAO.showScore(scoreId);
		BeanUtils.copyProperties(score, scoreVO);
		scoreVO.setUserName(score.getUser().getUserName());
		scoreVO.setSubjectName(score.getSubject().getName());
		scoreVO.setSubjectDescription(score.getSubject().getDescription());
		return scoreVO;
	}
	
}
